home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Include / FWOnStac.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  4.9 KB  |  158 lines  |  [TEXT/MPS ]

  1. #ifndef FWONSTAC_H
  2. #define FWONSTAC_H
  3. //========================================================================================
  4. //
  5. //    File:                FWOnStac.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #if !defined(FWPRIDEB_H) && defined(FW_BUILD_WIN)
  15. #include "FWPriDeb.h"
  16. #endif
  17.  
  18. #ifdef FW_BUILD_MAC
  19.  
  20. #if 1
  21. // Slow version for use if (_FW_PrivIsOnStack()) xxx; works for near and far data
  22. extern "C"
  23. {
  24.     #pragma parameter _FW_PrivIsOnStack(__A0)
  25.     int _FW_PrivIsOnStack(void *)
  26.         = {0x7000, 0xBFC8, 0x6408, 0xB1F8, 0x0908, 0x6202, 0x7001, 0x4880, 0x48C0};
  27. }
  28. /*
  29. 00000                              OnStackCheck PROC
  30. 00000                                      ;movea.l    a4,a0    ; 4 compiler generated move
  31. 00000   7000                               moveq    #0,d0
  32. 00002   BFC8                               cmpa.l    a0,a7
  33. 00004   6408            0000E              bcc.s    @1
  34. 00006   B1F8 0908                          cmpa.l    $908,a0
  35. 0000A   6202            0000E              bhi.s    @1
  36. 0000C   7001                               moveq    #1,d0
  37. 0000E                                  @1:
  38. 0000E   4880                               ext.w    d0
  39. 00010   48C0                               ext.l    d0
  40. 00012                                  ENDPROC
  41. */
  42. #endif
  43.  
  44. #if 0
  45. // Near data version
  46. extern "C"
  47. {
  48.     #pragma parameter _FW_PrivIsOnStack(__A0)
  49.     void _FW_PrivIsOnStack(void *)
  50.         = {0xBFC8, 0x6210, 0xB1F8, 0x0908, 0x620A};
  51. }
  52. /*
  53. 00000                              OnStack    PROC
  54. 00000                                      ;movea.l    a4,a0    ; 4 compiler generated move
  55. 00000   BFC8                               cmpa.l    a0,a7        ; 6
  56. 00002   6210            00014              bhi.s    @1            ; 10/8
  57. 00004   B1F8 0908                          cmpa.l    $908,a0        ; 6
  58. 00008   620A            00014              bhi.s    @1            ; 10/8
  59. 0000A   2F0C                               move.l    a4,-(a7)
  60. 0000C   486D 001E                          pea        30(a5)
  61. 00010   4EAD 001E                          jsr        30(a5)        ; 18
  62. 00014                                  @1:
  63. 00014   4E71                               nop
  64. 00016                                  ENDPROC
  65. */
  66. #endif
  67.  
  68. #if 0
  69. // Far data version for when the code is compiled with the -m option.
  70. extern "C"
  71. {
  72.     #pragma parameter _FW_PrivIsOnStack(__A0)
  73.     void _FW_PrivIsOnStack(void *)
  74.         = {0xBFC8, 0x6218, 0xB1F8, 0x0908, 0x6212};
  75. }
  76. /*
  77. 00000                              OnStackFar    PROC
  78. 00000                                      ;movea.l    a4,a0    ; 4 compiler generated move
  79. 00000   BFC8                               cmpa.l    a0,a7        ; 6
  80. 00002   6218            0001C              bhi.s    @1            ; 10/8
  81. 00004   B1F8 0908                          cmpa.l    $908,a0        ; 6
  82. 00008   6212            0001C              bhi.s    @1            ; 10/8
  83. 0000A   2F0C                               move.l    a4,-(a7)
  84. 0000C   204D                               movea.l    a5,a0
  85. 0000E   D1FC 0001 0000                     adda.l    #-$FFFF0000,a0
  86. 00014   4855                               pea        (a5)
  87. 00016   4EAD 001E                          jsr        30(a5)        ; 18
  88. 0001A   504F                               addq    #8,a7
  89. 0001C                                  @1:
  90. 0001C   4E71                               nop
  91. 0001E                                  ENDPROC
  92. */
  93. #endif
  94.  
  95. #endif
  96.  
  97. #ifdef FW_BUILD_WIN
  98. #ifdef FW_BUILD_WIN16
  99. //----------------------------------------------------------------------------------------
  100. //    WinGetStackBottom
  101. //----------------------------------------------------------------------------------------
  102. inline unsigned short *WinGetStackBottom()
  103. {
  104.     __emit__(0x8C, 0xD2);                // mov DX, SS        2 cycles
  105. #ifndef __BORLANDC__                    
  106.     return (void*)    
  107. #endif
  108.     __emit__(0xB8, 0x0E, 0x00);            // mov AX, 0Eh        2 cycles
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. //    WinGetStackTop
  113. //----------------------------------------------------------------------------------------
  114. inline unsigned short *WinGetStackTop()
  115. {
  116.     __emit__(0x8C, 0xD2);            // mov DX, SS        2 cycles
  117. #ifndef __BORLANDC__                    
  118.     return (void*)    
  119. #endif    
  120.     __emit__(0xB8, 0x0A, 0x00);        // mov AX, 0Ah        2 cycles
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. // _FW_PrivSegmentOf
  125. //----------------------------------------------------------------------------------------
  126. inline unsigned short _FW_PrivSegmentOf(void* p)
  127. {
  128.     return (unsigned short)((unsigned long)p >> 16);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // _FW_PrivOffsetOf
  133. //----------------------------------------------------------------------------------------
  134. inline unsigned short _FW_PrivOffsetOf(void* p)
  135. {
  136.     return (unsigned short) p;
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // _FW_PrivIsOnStack
  141. //----------------------------------------------------------------------------------------
  142. inline int _FW_PrivIsOnStack(void * p)
  143. {
  144.     int i;
  145.     if (_FW_PrivSegmentOf(p) != _FW_PrivSegmentOf(&i))
  146.         return 0;
  147.     unsigned short top = *WinGetStackTop();
  148.     unsigned short bot = *WinGetStackBottom();
  149.     unsigned short offset = _FW_PrivOffsetOf(p);
  150.     return (offset>top && offset<bot);
  151. }
  152. #else
  153. int _FW_PrivIsOnStack(void * p);
  154. #endif
  155. #endif
  156.  
  157. #endif
  158.